const DBUtil = require('../dbUtil')


function list(callback) {

    const sql = "SELECT * FROM foods.role limit 5";

    DBUtil.query(sql, null, function (err, rows) { //执行sql语句
        callback(rows)
    })

}


function insert(role,callback){
     let sql  = "insert into role(role_name,is_used) value(?,?) ";

     let params = [role.role_name,role.is_used];

     DBUtil.query(sql,params,function(err,result){
         callback(result);
     })

}


function update(role,callback){

    let sql ='update role set role_name=?, is_used=? where role_id =?';
    let params = [role.role_name,role.is_used,role.role_id];

    DBUtil.query(sql,params,function(err,result){
        callback(result);
    })

}


function remove (role,callback){

    let sql ='delete from role where role_id =?';
    let params = [role.role_id];

    DBUtil.query(sql,params,function(err,result){
        callback(result);
    })


    console.log(sql+ "role_id:"+role.role_id);

}

module.exports = {
     list,
     insert,
     update,
     remove
}